#include "TCPServer.hpp"
#include "ServerCal.hpp"
#include "Protocol.hpp"
#include <unistd.h>

static void Usage(const std::string& proc)
{
    std::cout << "\nUsage: " << proc << " port\n\n" << std::endl;
}

int main(int argc, char* argv[])
{
    if(argc != 2)
    {
        Usage(argv[0]);
        exit(0);
    }
    uint16_t port = std::stoi(argv[1]);


    SerCal cal;
    TCPServer *tsvp = new TCPServer(port, std::bind(&SerCal::calculator,&cal,std::placeholders::_1));
    tsvp->InitServer();
    daemon(0,0);
    tsvp->start();
    // Response res(1000, 0);
    // std::string content;
    // res.Serialize(&content); 
    // std::cout << content << std::endl;

    // std::string package = Encode(content);
    // std::cout << package;

    // content = "";
    // bool r = Decode(package,&content);
    // std::cout << content << std::endl;

    // Response tmp;
    // tmp.Deserialize(content);
    // std::cout << tmp.result << std::endl;
    // std::cout << tmp.status << std::endl;



    // Request req(123,456,'+');    
    // std::string s;
    // req.Serialize(&s);
    // s = Encode(s);
    // std::cout << s;



    // std::string content;
    // bool r = Decode(s, &content);
    // std::cout << content << std::endl;

    // Request tmp;
    // tmp.Deserialize(content);

    // std::cout << tmp.x << std::endl;
    // std::cout << tmp.op << std::endl;
    // std::cout << tmp.y << std::endl;


    return 0;
}